package com.dd.web;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;

public class PreRequestFilter extends ZuulFilter {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(PreRequestFilter.class);
	
	/**
	 * 过滤器要执行的具体方法
	 */
	public Object run() {
		System.out.println("前置zuul过滤器执行");
		RequestContext rct= RequestContext.getCurrentContext();
		HttpServletRequest request = rct.getRequest();
		PreRequestFilter.LOGGER.info(String.format("send %s request to %s", request.getMethod(),request.getRequestURL().toString()));
		return null;
	}
	
	
	/**
	 * 是否使用
	 */
	public boolean shouldFilter() {
		return true;
	}
	
	/**
	 * 执行顺序
	 */
	@Override
	public int filterOrder() {
		return 1;
	}
	
	/**
	 * 过滤器类型
	 */
	@Override
	public String filterType() {
		return "pre";
	}

}
